package com.cloudfun.campusshare.listener;

import com.cloudfun.campusshare.common.constant.RabbitConstants;
import com.cloudfun.campusshare.service.DeviceService;
import com.cloudfun.msgsubscribe.DeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by Huqin on 2020/3/31
 */
@Slf4j
@Component
@RabbitListener(queues = RabbitConstants.Queue.DEVICE_FIRMWARE)
public class DeviceFirmwareMsgListener extends AbstractDeviceMsgListener {

    @Autowired
    private DeviceService deviceService;

    @Override
    protected void doProcess(DeviceInfo deviceInfo) {
        log.info("收到2G设备固件消息：{}", deviceInfo);
        Map<String, String> attrs = deviceInfo.getAttrs();
        if (attrs.containsKey("iccid")) {
            deviceService.updateDeviceIccid(deviceInfo.getImei(), attrs.get("iccid"));
        }
    }

}
